import test from 'node:test'
import { type } from 'os'
import { h, render } from 'vue'
import XtxMessage from './message.vue'
type obj = {
  type: 'success' | 'error' | 'warning'
  text: string
  duration?: number
}

const div = document.createElement('div')
document.body.appendChild(div)
function Message({ type, text, duration = 2000 }: obj) {
  const vnode = h(XtxMessage, { type, text })
  render(vnode, div)

  setTimeout(() => {
    render(null, div)
  }, duration)
}

Message.error = (text: string, duration = 2000) => {
  Message({
    type: 'error',
    text,
    duration
  })
}

Message.success = (text: string, duration = 2000) => {
  Message({
    type: 'success',
    text,
    duration
  })
}

Message.warning = (text: string, duration = 2000) => {
  Message({
    type: 'warning',
    text,
    duration
  })
}

export default Message
